﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CXedu.Model;
using CXedu.Business;
using CXedu.WebSite.Code;
using Ajeelee.Core.Utils;

namespace CXedu.WebSite
{
    public partial class join : Code.PageBase
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (IsPost)
            {
                string code = "";
                try
                {
                    code = Request.Cookies["VCode"].Value.SimpleDecryp().ToLower();
                }
                catch (Exception ex) { }
                if (FormParam("utype").IsNotNullAndEmpty() && FormParam("code").ToLower() == code)
                {
                    try
                    {
                        SetCookie("VCode", null, DateTime.Now.AddDays(-30));

                        IStudentBusiness studentBll = new StudentBusinessFactory().CreateStudentBusiness();
                        Student student = new Student();
                        student.Name = FormParam("name");
                        student.Phone = FormParam("tel");
                        student.QQ = FormParam("qq");
                        student.Email = FormParam("email");
                        student.Type = FormParam("utype");
                        student.Time = DateTime.Now;
                        student.State = 1;
                        student.Content = Utility.StripHTML(FormParam("uother"));
                        studentBll.Insert(student);
                        MessageBoxGo("提交成功！", "/join.aspx");
                    }
                    catch (System.Threading.ThreadAbortException ex) { }
                    catch (Exception ex)
                    {
                        Function.WriteErrorLog(ex);
                    }
                }
                else
                {
                    MessageBack("验证码错误或过期！");
                }
            }
        }
    }
}